package mobi.hami.huapin.dao;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.model.UserOrderDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Create by 小峰 on 2018/9/1.
 */
@Repository
public interface UserOrderDetailMapper extends CrudMapper<UserOrderDetail> {

    @Select("select * from user_order_detail where order_id=#{id} and sku_type=0")
    List<UserOrderDetail> getListbyOrderId(Integer id);

    /**
     * 返回所有信息，包括赠品
     * @param id
     * @return
     */
    @Select("select * from user_order_detail where order_id=#{id} ")
    List<UserOrderDetail> getListbyOrderIdAll(Integer id);

    @Insert("<script> INSERT INTO user_order_detail(order_id,sku_id,sku_name,attribute_name,sku_photo,sku_money,sku_cout) Values\n" +
            "<foreach item='item' collection='userOrderDetailList' separator=\",\"> " +
            " (" +
            " #{orderId}," +
            " #{item.sku_id}," +
            " #{item.sku_name}," +
            " #{item.attribute_name}," +
            " #{item.sku_photo}," +
            " #{item.sku_money}," +
            " #{item.sku_cout})" +
            "</foreach></script>")
    int addList(@Param("userOrderDetailList") List<UserOrderDetail> userOrderDetailList, @Param("orderId")Integer orderId);
}
